<template>
	<view class="box">
		<page-head :transparent='false'>
		    <slot slot="title">{{title.length>10?title.substr(0,10)+'...':title}}</slot>
		</page-head>
		<view class="img1">
			<image class="img-buy" src="../../static/img/guidance/0yuan2.jpg" mode="widthFix"></image>
		</view>
		<brand-goods-list :goodsList="goodsList" :loadingText="loadingText" @eventClick="toGoodsDetail"></brand-goods-list>
	</view>
</template>

<script>
	import BrandGoodsList from '../../components/brand-goods-list.vue';
	let page = 10,
		pagesize = 20;
	export default {
		components: {
			BrandGoodsList
		},
		data() {
			return {
				goodsList: [],
				loadingText: '加载中...',
				title:''
			};
		},
		onLoad(event) {
			page = 10;
			// document.title = '';
			this.genList();
			if (event.token != '' && event.token != 'null' && event.token != null && event.token != undefined && event.token !=
			    'undefined') {
			    uni.setStorageSync('token', decodeURI(event.token));
			}
		},
		onReachBottom() {
			this.genList();
		},
		methods: {
			setTitle(title) {
				uni.setNavigationBarTitle({
					title: title
				});
			},
			async genList() {
				try {
					let data = { pageno: page, pagesize: pagesize };
					let res = await this.$request.post('/coupon-product/myq/tbGoods/qualityCouponGoods', { data: data });
					let datas = res.data;
					let newList = datas.data;
					if (newList != '' && newList.length > 0) {
						this.goodsList = this.goodsList.concat(newList);
						page++;
						if (page == 500 || newList.length < 19) {
							this.loadingText = '没有更多了';
						}
					} else {
						this.loadingText = '没有更多了';
					}
				} catch (e) {
					console.log(e);
					this.loadingText = '没有更多了';
				}
			},
			toGoodsDetail(e) {
				let startTime = new Date(parseInt(e.coupon_start_time)).toLocaleString().substr(0, 9);
				let endTime = new Date(parseInt(e.coupon_end_time)).toLocaleString().substr(0, 9);
				uni.navigateTo({
					url:
						'../tbdetail/tbdetail?skuId=' +
						e.item_id +
						'&cid=0' +
						'&title=1' +
						'&seller=淘宝' +
						'&coupon_amount=' +
						e.coupon_amount +
						'&startTime=' +
						startTime +
						'&endTime=' +
						endTime +
						'&tm=false'
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.box{
		width: 100%;
		
		.img1{
			width: 100%;
			overflow: hidden;
			overflow-y: auto;
			
			.img-buy{
				width: 100%;
				display: block;
			}
		}
	}
</style>
